package net.csdn.business.discuss.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.discuss.api.model.entity.DiscussVoteOption;
import net.csdn.business.discuss.api.model.query.DiscussVoteOptionQuery;
import net.csdn.business.discuss.api.model.vo.DiscussVoteOptionVO;
import org.apache.ibatis.annotations.*;

import java.util.LinkedList;
import java.util.List;

/**
 * 投票选项Mapper接口
 * 
 * @author ruoyi
 * @date 2023-07-25
 */
public interface DiscussVoteOptionMapper extends BaseMapper<DiscussVoteOption>
{

    /**
     * 分页查询投票选项列表
     *
     * @param query 字典类型信息
     * @return 字典类型集合信息
     */
    public List<DiscussVoteOptionVO> findPageList(Page page, @Param("query") DiscussVoteOptionQuery query);

    /**
     * 查询投票选项
     * 
     * @param id 投票选项主键
     * @return 投票选项
     */
    @Select("select * from discuss_vote_option where object_id=#{id}")
    public DiscussVoteOptionVO selectDiscussVoteOptionById(@Param("id")String id);

    /**
     * 查询投票选项列表
     * 
     * @param discussId 讨论主键
     * @return 投票选项集合
     */
    @Select("select * from discuss_vote_option where discuss_id=#{discussId} order by option_order asc")
    public LinkedList<DiscussVoteOptionVO> selectVoteOptionList(@Param("discussId") String discussId);

    /**
     * 新增投票选项
     * 
     * @param discussVoteOption 投票选项
     * @return 结果
     */
    public Integer insertDiscussVoteOption(DiscussVoteOption discussVoteOption);

    /**
     * 批量插入投票选项
     *
     * @param options 投票选项集合
     * @return 结果
     */
    @Insert({
            "<script>",
            "INSERT INTO discuss_vote_option(object_id, vote_option,option_order,vote_id,discuss_id,created_by) VALUES ",
            "<foreach collection='options' item='option' separator=','>",
            "(#{option.objectId}, #{option.voteOption}, #{option.optionOrder}, #{option.voteId}, #{option.discussId}, #{option.createdBy})",
            "</foreach>",
            "</script>"
            })
    public Integer addBatch(@Param("options")List<DiscussVoteOption> options);

    /**
     * 修改投票选项
     * 
     * @param discussVoteOption 投票选项
     * @return 结果
     */
    public Integer updateDiscussVoteOption(DiscussVoteOption discussVoteOption);

    /**
     * 删除投票选项
     * 
     * @param discussId 讨论主键
     * @return 结果
     */
    @Delete("delete from discuss_vote_option where discuss_id=#{discussId}")
    public Integer deleteVoteOptionByDiscussId(@Param("discussId")String  discussId);


    @Update("update discuss_vote_option set vote_total=vote_total+ #{sum}  where  object_id=#{optionId}")
    public Integer addVoteTotal(@Param("optionId")String optionId,@Param("sum")Integer sum);

}
